home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.05 May 91 / Math Parser ƒ / Node Stuff / CheckLine next >
Encoding:
Text File  |  1990-10-30  |  3.6 KB  |  157 lines  |  [TEXT/PJMM]

  1. unit CheckLine;
  2.  
  3. interface
  4.  
  5.     uses
  6.         ParserGlobals, Parser, SetValues, EvaluateNodes;
  7.  
  8.     procedure checkline (var ntot: integer; var sy, tokentype: hdlstringarray0; var pr: hdlintarray0; var numnodes: integer; var t: hdlextendarray; var error: str255);
  9.  
  10.  
  11. implementation
  12.  
  13.  
  14.     procedure checkline;
  15.  
  16.         label
  17.             998, 999;
  18.  
  19.         var
  20.             i, j, k, l, nstart: integer;
  21.             flag: hdlflagtype;
  22.             save: array2;
  23.             nodetable: hdlnoderecord;
  24.             realnumber: extended;
  25.             store: boolean;
  26.  
  27.     begin
  28.  
  29.         nstart := 0;
  30.  
  31.         store := false;
  32.  
  33.         nodetable := hdlnoderecord(NewHandle(SizeOf(noderecord)));
  34.         flag := hdlflagtype(NewHandle(SizeOf(flagtype)));
  35.  
  36.         if (sy^^[1] = 'pi') and (sy^^[2] = equals) then
  37.             begin
  38.                 writeln(sy^^[1], '  is a built-in constant. Define another variable, please.');
  39.                 goto 999;
  40.             end;
  41.  
  42.         if ((sy^^[1] = 'listv') or (sy^^[1] = 'stop')) and (sy^^[2] = equals) then
  43.             begin
  44.                 writeln(sy^^[1], '  is a command word. Define another variable, please.');
  45.                 goto 999;
  46.             end;
  47.  
  48.         if (sy^^[2] = equals) then
  49.             nstart := 3;
  50.  
  51.         for i := nstart to ntot do
  52.             begin
  53.                 flag^^[i] := false;
  54.  
  55.                 if (ntot = 4) and (sy^^[1] = '(') and (sy^^[3] = ')') then
  56.                     if sy^^[2] <> 'pi' then
  57.                         begin
  58.                             readstring(sy^^[2], realnumber);
  59.                             writeln(realnumber : decplaceplus10 : decplace);
  60.                             goto 999;
  61.                         end;
  62.  
  63.                 if ntot = 2 then
  64.                     if (tokentype^^[1] = 'constant') then
  65.                         begin
  66.                             if sy^^[1] = 'pi' then
  67.                                 writeln(pivalue : decplaceplus10 : decplace);
  68.                             if sy^^[1] <> 'pi' then
  69.                                 begin
  70.                                     readstring(sy^^[1], realnumber);
  71.                                     writeln(realnumber : decplaceplus10 : decplace);
  72.                                 end;
  73.                             goto 999;
  74.                         end;
  75.  
  76.                 if (numvariables > 0) then
  77.                     begin
  78.  
  79.                         for k := 1 to numvariables do
  80.                             begin
  81.                                 j := numvariables + 1 - k;
  82.                                 if (sy^^[i] = strvar^^[j]) and (tokentype^^[i] = 'variable') then
  83.                                     begin
  84.                                         flag^^[i] := true;
  85.                                         tokentype^^[i] := strvartokentype^^[j];
  86.  
  87.                                         if (ntot = 2) then
  88.                                             begin
  89.                                                 if ((strvartokentype^^[j] = 'real') or (strvartokentype^^[j] = 'variable')) then
  90.                                                     writeln(val^^[j] : decplaceplus10 : decplace);
  91.                                                 goto 999;
  92.                                             end;
  93.  
  94.                                         if (ntot = 4) and (sy^^[1] = '(') and (sy^^[3] = ')') then
  95.                                             begin
  96.                                                 if ((strvartokentype^^[j] = 'real') or (strvartokentype^^[j] = 'variable')) then
  97.                                                     writeln(val^^[j] : decplaceplus10 : decplace);
  98.                                                 goto 999;
  99.                                             end;
  100.  
  101.  
  102.                                         goto 998;
  103.                                     end;
  104.                             end;
  105.                     end;
  106. 998:
  107.             end;
  108.  
  109.         save[1] := sy^^[1];
  110.         save[2] := sy^^[2];
  111.  
  112.         for i := nstart to ntot do
  113.             begin
  114.                 if ((tokentype^^[i] = 'variable') or (tokentype^^[i] = 'real')) and (flag^^[i] = false) then
  115.                     begin
  116.                         if ntot = 2 then
  117.                             writeln(sy^^[i]);
  118.                         if ntot > 2 then
  119.                             writeln('  ', sy^^[i], '  has not been defined ');
  120.                         goto 999;
  121.                     end;
  122.  
  123.                 if tokentype^^[i] = 'constant' then
  124.                     if (sy^^[i] <> 'pi') then
  125.                         for j := 1 to length(sy^^[i]) do
  126.                             if (((65 <= ord(sy^^[i][j])) and (ord(sy^^[i][j]) <= 90)) or ((97 <= ord(sy^^[i][j])) and (ord(sy^^[i][j]) <= 122))) and (sy^^[i][j] <> 'E') and (sy^^[i][j] <> 'e') then
  127.                                 begin
  128.                                     writeln('  ', sy^^[i], '  has not been defined');
  129.                                     error := ' ';
  130.                                     goto 999;
  131.                                 end;
  132.             end;
  133.  
  134.         parser(ntot, sy, tokentype, pr, nodetable, numnodes, error);
  135.  
  136.         if error <> '' then
  137.             goto 999;
  138.  
  139.         setvalues(nodetable, numnodes, numvariables);
  140.  
  141.         if save[2] = equals then
  142.             store := true;
  143.  
  144.         evaluatenodes(nodetable, numnodes, t, store, save, error);
  145.  
  146.         if error <> '' then
  147.             goto 999;
  148.  
  149.  
  150. 999:
  151.         DisposHandle(handle(nodetable));
  152.         DisposHandle(handle(flag));
  153.  
  154.     end;
  155.  
  156.  
  157. end.